package com.simpleim.im.common.bean;

import com.simpleim.im.common.bean.msg.ProtoMsg;

import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

public class User {

    private static final AtomicInteger NO = new AtomicInteger(0);

    private String uid = String.valueOf(NO.getAndDecrement());

    private String devId = UUID.randomUUID().toString();

    private String token = UUID.randomUUID().toString();

    private String nickName = "nickName";

    private String sessionId;

    private PLATTYPE platform = PLATTYPE.WEB;

    public static enum PLATTYPE {
        WINDOWS,
        MAC,
        ANDROID,
        IOS,
        WEB,
        UNKNOWN
    }

    public void setPlatform(int platform) {
        PLATTYPE[] values = PLATTYPE.values();
        for (PLATTYPE value : values) {
            if (value.ordinal() == platform) {
                this.platform = value;
            }
        }
    }

    @Override
    public String toString() {
        return "User{" +
                "uid='" + uid + '\'' +
                ", devId='" + devId + '\'' +
                ", token='" + token + '\'' +
                ", sessionId='" + sessionId + '\'' +
                ", platform=" + platform +
                '}';
    }

    public static User fromMsg(ProtoMsg.LoginRequest info) {
        User user = new User();
        user.setDevId(info.getDeviceId());
        user.setPlatform(info.getPlatform());
        user.setUid(info.getUserId());
        user.setToken(info.getToken());
        return user;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public String getDevId() {
        return devId;
    }

    public void setDevId(String devId) {
        this.devId = devId;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getSessionId() {
        return sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    public PLATTYPE getPlatform() {
        return platform;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }
}
